package com.tt.vtg.utils;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class RandomGenerator {
	private static final String randomContent;
	private static final int randomLength = 20;
	private Random random;
	private RandomGenerator(){random = new Random();}
	static{
		randomContent = "1234567890abcdefghikmnopqrstuvwxyz=-!";
	}
	
	public String generate(){
		StringBuffer sb = new StringBuffer();
		getRandomNumbers().forEach(s->sb.append(s));
		return sb.toString();
	}
	
	private Set<String> getRandomNumbers() {
        Set<String> set = new HashSet<String>();
        int arrayLength = randomContent.length();
        while (true) {
            if (set.size() < randomLength) {
                set.add(String.valueOf(randomContent.charAt(random.nextInt(arrayLength))));
            } else {
                break;
            }
        }
        return set;
    }
	
	public static RandomGenerator getInstance(){
		return RandomGenSingleton.INSTANCE.get();
	}
	
	private static enum RandomGenSingleton{
		INSTANCE;
		private RandomGenerator ins;
		RandomGenSingleton(){
			ins = new RandomGenerator();
		}
		public RandomGenerator get(){
			return ins;
		}
	}
}
